package com.jk.order.controller;

import com.jk.common.model.AddressBean;
import com.jk.common.model.ChinaAddressBean;
import com.jk.common.model.FlowerBean;
import com.jk.common.model.OrderBean;
import com.jk.order.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("order")
public class OrderController {

    private Logger logger = LoggerFactory.getLogger(OrderController.class);

    @Autowired
    private OrderService orderService;

    /**
     * 省级获取
     * @return
     */
    @RequestMapping("getProviceBind")
    public List<ChinaAddressBean> getProviceBind(Integer pid){
        List<ChinaAddressBean> list=   orderService.getProviceBind(pid);
        return  list;
    }

    /**
     * 新增收货人地址
     * @param addressBean
     */
    @RequestMapping("saveUserAddress")
    public  void saveUserAddress(@RequestBody AddressBean addressBean){

        orderService.saveUserAddress(addressBean);
    }

    /**
     * 生成订单id
     * @param
     * @param
     * @return
     */
    @RequestMapping("generateOrderId")
    public Map generateOrderId(String userId,String flowerIds){

          Map map=  orderService.generateOrderId(userId,flowerIds);
        return   map;
    }

    /**
     * 订单提交 存到mongodb中
     * @param orderBean
     */
    @RequestMapping("orderSave")
    public  Boolean orderSave(@RequestBody OrderBean orderBean){
         try {
             orderService.orderSave(orderBean);
             return  true;
         }catch (Exception e){
             e.printStackTrace();
             return  false;
         }
    }

    /**
     * 查询收货人地址
     * @param userId
     * @return
     */
    @RequestMapping("findUserAddress")
    public  AddressBean findUserAddress(String userId){
        AddressBean plist = orderService.findUserAddress(userId);
        return  plist;
    }


    //查询mongdb中的数据
    @RequestMapping("orderNumber")
    public OrderBean  orderNumber(String orderNumber){
      return  orderService.orderNumber(orderNumber);
    }

    //修改mongdb中的支付状态
    @RequestMapping("saveOrder")
    public  void  saveOrder(String orderNumber){
        orderService.saveOrder(orderNumber);
    }

    /**
     * 查询FlowerBean 鲜花 全部 为存到mongodb 做准备
     * @param flowerId
     * @return
     */
    @RequestMapping("queryFlowerPrice")
    public FlowerBean queryFlowerPrice(Integer flowerId){

        FlowerBean flowerBean=  orderService.queryFlowerPrice(flowerId);
        return flowerBean;
    }

}
